package cn.iocoder.yudao.module.member.controller.admin.studentEducationalExperience;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.member.controller.admin.studentEducationalExperience.vo.*;
import cn.iocoder.yudao.module.member.dal.dataobject.studentEducationalExperience.StudentEducationalExperienceDO;
import cn.iocoder.yudao.module.member.convert.studentEducationalExperience.StudentEducationalExperienceConvert;
import cn.iocoder.yudao.module.member.service.studentEducationalExperience.StudentEducationalExperienceService;

@Api(tags = "管理后台 - 用户简历教育经历")
@RestController
@RequestMapping("/member/student-educational-experience")
@Validated
public class StudentEducationalExperienceController {

    @Resource
    private StudentEducationalExperienceService studentEducationalExperienceService;

    @PostMapping("/create")
    @ApiOperation("创建用户简历教育经历")
    @PreAuthorize("@ss.hasPermission('member:student-educational-experience:create')")
    public CommonResult<Long> createStudentEducationalExperience(@Valid @RequestBody StudentEducationalExperienceCreateReqVO createReqVO) {
        return success(studentEducationalExperienceService.createStudentEducationalExperience(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新用户简历教育经历")
    @PreAuthorize("@ss.hasPermission('member:student-educational-experience:update')")
    public CommonResult<Boolean> updateStudentEducationalExperience(@Valid @RequestBody StudentEducationalExperienceUpdateReqVO updateReqVO) {
        studentEducationalExperienceService.updateStudentEducationalExperience(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除用户简历教育经历")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('member:student-educational-experience:delete')")
    public CommonResult<Boolean> deleteStudentEducationalExperience(@RequestParam("id") Long id) {
        studentEducationalExperienceService.deleteStudentEducationalExperience(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得用户简历教育经历")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('member:student-educational-experience:query')")
    public CommonResult<StudentEducationalExperienceRespVO> getStudentEducationalExperience(@RequestParam("id") Long id) {
        StudentEducationalExperienceDO studentEducationalExperience = studentEducationalExperienceService.getStudentEducationalExperience(id);
        return success(StudentEducationalExperienceConvert.INSTANCE.convert(studentEducationalExperience));
    }

    @GetMapping("/list")
    @ApiOperation("获得用户简历教育经历列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('member:student-educational-experience:query')")
    public CommonResult<List<StudentEducationalExperienceRespVO>> getStudentEducationalExperienceList(@RequestParam("ids") Collection<Long> ids) {
        List<StudentEducationalExperienceDO> list = studentEducationalExperienceService.getStudentEducationalExperienceList(ids);
        return success(StudentEducationalExperienceConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得用户简历教育经历分页")
    @PreAuthorize("@ss.hasPermission('member:student-educational-experience:query')")
    public CommonResult<PageResult<StudentEducationalExperienceRespVO>> getStudentEducationalExperiencePage(@Valid StudentEducationalExperiencePageReqVO pageVO) {
        PageResult<StudentEducationalExperienceDO> pageResult = studentEducationalExperienceService.getStudentEducationalExperiencePage(pageVO);
        return success(StudentEducationalExperienceConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出用户简历教育经历 Excel")
    @PreAuthorize("@ss.hasPermission('member:student-educational-experience:export')")
    @OperateLog(type = EXPORT)
    public void exportStudentEducationalExperienceExcel(@Valid StudentEducationalExperienceExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<StudentEducationalExperienceDO> list = studentEducationalExperienceService.getStudentEducationalExperienceList(exportReqVO);
        // 导出 Excel
        List<StudentEducationalExperienceExcelVO> datas = StudentEducationalExperienceConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "用户简历教育经历.xls", "数据", StudentEducationalExperienceExcelVO.class, datas);
    }

}
